package com.zznzzn.myweb.controller;

import com.zznzzn.myweb.pojo.RespModel;
import com.zznzzn.myweb.util.RespHelper;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ErrorController implements org.springframework.boot.web.servlet.error.ErrorController {

    @RequestMapping("/error")
    public RespModel<Object> handleError(@RequestParam(value = "error",required = false,defaultValue = "404") String error){
        if (error!=null ){
            if (error.equals("401")){
                return RespHelper.buildUnauthorizated();
            }
        }
        return RespHelper.buildNotFound();
    }

    @Override
    public String getErrorPath() {
        return "/error";
    }
}
